#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/9/3 15:10
# @Author : 吴敬超
# explain:
import netCDF4 as nc
import numpy as np
# file_path = 'D:/ehlocean/data/TEMPSALT/SALT_B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.pop.h.0021-01.nc'

# URL of an OpenDAP  OpenDAP 的url可以
file_path = 'http://192.168.22.44:8080/thredds/dodsC/treefile/oceansnap/ocean_snap_salt_2018_02_01.nc'

# file_path = 'D:/hy1s/tochech/ocean_snap_salt_2018_02_01.nc'


# file_path = 'D:\NetCDFfile\盐度三个月经纬度均匀处理后数据\SALT_B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.pop.h.0021-01.nc'
file_obj = nc.Dataset(file_path)
print('---------------file_obj------------------------')
# print(file_obj)
print('---------------file_obj------------------------')
#
# #查看nc文件中的变量
# print(file_obj.variables.keys())
# for i in file_obj.variables.keys():
#     print(i)
# print('---------------------------------------')
#
# QCHANR_ICE = file_obj.variables['QCHANR_ICE'][:]
# # str(QCHANR_ICE[0][3][3])
# print('---------------QCHANR_ICE------------------------')
#
# print "QCHANR_ICE[0][3][3] is:" +str(QCHANR_ICE[0][3][3])
# print "QCHANR_ICE[0][4][4] is:" +str(QCHANR_ICE[0][4][4])
# v = file_obj.variables['v'][:]
# print "v[0][0][3][3] is:" +str(v[0][0][3][3])
# print "v[0][0][4][4] is:" +str(v[0][0][4][4])

# st_edges_ocean = file_obj.variables['st_edges_ocean'][:]
# print " is:" +str(st_edges_ocean[7])
#
#

# salt = file_obj.variables['salt'][:]

# 一次性读取太大，分片读取
# 存在数据精度问题，自动匹配数据类型，都是数据默认6位，
salt = file_obj.variables['salt'][0,0, 2500:2510, 11500:11600]

print salt
# print str(salt[0][0])

#
# print "v[0][0][3][3] is:" + str(salt[0][0][2540][11513])
# print "v[0][0][4][4] is:" + str(salt[0][0][2538][11516])

#

# xt_ocean = file_obj.variables['xt_ocean'][:]
#
# print len(xt_ocean)
# print  type(xt_ocean)
file_obj.close()
